const md5 = require('md5')
// var _0x589add = "3300069499" // _0x28b110["bookId"]
//     , _0x1241c7 = 23 // '章节id' _0x4240a8["get"](_0x48cc3f, "chapterUid");

function getMd5(param) {
    param = param.toString()
    let md5_data = md5(param)
    let md5_substr = md5_data.substring(0, 3)
    let md52Arr = function (v) {
        if (/^\d*$/["test"](v)) {
            var _0x40d54f = v["length"], arr = []
            for (let i = 0; i < _0x40d54f; i += 9) {
                var slice_data = v["slice"](i, Math["min"](i + 9, _0x40d54f));
                arr["push"](parseInt(slice_data)["toString"](16))
            }
            return ["3", arr]
        }
        let STR = ""
        for (let i = 0; i < v["length"]; i++)
            STR += v["charCodeAt"](i)['toString'](16);
        return ["4", [STR]]
    }(param);
    // console.log(md52Arr)
    md5_substr += md52Arr[0],
        md5_substr += 2 + md5_data["substr"](md5_data["length"] - 2, 2);
    var data = md52Arr[1]
    for (let i = 0; i < data["length"]; i++) {
        var hexStr = data[i]["length"]["toString"](16);
        1 === hexStr["length"] && (hexStr = "0" + hexStr),
            md5_substr += hexStr,
            md5_substr += data[i],
        i < data['length'] - 1 && (md5_substr += "g")
    }
    return md5_substr['length'] < 20 && (md5_substr += md5_data["substr"](0, 20 - md5_substr["length"])),
        md5_substr += md5(md5_substr)["substr"](0, 3)
}
function getS(strP){
    for (var _0x404e92 = 352654597, _0x4ea431 = _0x404e92, _0x535eb2 = strP['length'], _0x153036 = _0x535eb2 - 1; _0x153036 > 0; _0x153036 -= 2)
        _0x404e92 = 2147483647 & (_0x404e92 ^ strP["charCodeAt"](_0x153036) << (_0x535eb2 - _0x153036) % 30),
            _0x4ea431 = 2147483647 & (_0x4ea431 ^ strP["charCodeAt"](_0x153036 - 1) << _0x153036 % 30);
    return (_0x404e92 + _0x4ea431)["toString"](16)["toLowerCase"]()

}
function getPyload(bookId,chapterUid,ps,pc){
    let b = getMd5(bookId)
    let c = getMd5(chapterUid)
    let r = Math["pow"](parseInt(10000 * Math['random']()), 2)
    let st = 0
    let ct = parseInt(new Date()["getTime"]() / 1000)
    // let ps =
    // let pc = getMd5()

    let strParam = "b="+b+"&c="+c+"&ct="+ct+"&pc="+pc+"&ps="+ps+"&r="+r+"&st=0"
    let s = getS(strParam)
    return {'b':b,'c':c,'r':r,'st':0,'ct':ct,'ps':ps,'pc':pc,'s':s}
}
function getUrlParam(bid,cid){
    return [
        getMd5(bid),
        getMd5(cid)
    ]
}
// console.log(getMd5(47064752))
'f6f325707a18adeag017277'

